using System.Threading.Tasks;
using HengTong.Model.Request;
using Microsoft.AspNetCore.Mvc;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using WalkingTec.Mvvm.Mvc;
using HengTong.ViewModel.Hr.SysAttendanceRecordVms;
using TiaoTaoHelper.Wtm.Attributes;


namespace HengTong.Areas.Hr.Controllers
{
    public partial class SysAttendanceRecordController : BaseApiController
    {
        [ActionDescription("按人员查询")]
        [HttpPost("SearchByPerson")]
		public IActionResult SearchByPerson(SysAttendanceRecordByPersonSearcher searcher)
        {
            if (ModelState.IsValid)
            {
                var vm = Wtm.CreateVM<SysAttendanceRecordByPersonListVm>(passInit: true);
                vm.Searcher = searcher;
                return Ok(vm.GetJsonForApi());
            }
            else
            {
                return BadRequest(ModelState.GetErrorJson());
            }
        }
        
        
        [PreventDuplicateSubmit]
        [ActionDescription("人工排班")]
        [HttpPost("BatchChange")]
        public async Task<IActionResult> BatchChange([FromBody]AddAttendanceRecordsRequest request)
        {
            if (ModelState.IsValid)
            {
                var vm = Wtm.CreateVM<SysAttendanceRecordBatchVm>();
                if (await vm.DoBatchAddAsync(request))
                {
                    return Ok();
                }
            }
            return BadRequest(ModelState.GetErrorJson());
        }
    }
}
